﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Sim
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
            skinEngine1.SkinFile = "Skins\\office2007.ssk";

        }
        //退出按钮
        private void button2_Click(object sender, EventArgs e)
        {
            var res = MessageBox.Show("是否退出系统？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (res.Equals(DialogResult.Yes))
            {
                Environment.Exit(0);
            }
            else
            {
                return;
            }
        }

        //登入按钮
        private void button1_Click(object sender, EventArgs e)
        {
            BookManage BookManage = new BookManage();//管理系统界面

            string sql = string.Format("Select * from Users where Username='{0}' and Password='{1}'",textBox1.Text,textBox2.Text);

            //执行SQL语句
            var dt = DbHelper.GetDbHelper(sql);

            //判断SQL语句是否执行成功
            if (dt.Rows.Count == 1)
            {
                MessageBox.Show("登录成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                BookManage.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("登录失败！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

            }
        }

        //注册按钮
        private void button3_Click(object sender, EventArgs e)
        {
            this.Hide();
            Register register = new Register();
            register.Show();
        }

        //在密码框按下Enter键登入
        private void textBox2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                button1_Click(sender, e);
            }
        }

        //右上角红叉事件
        private void Login_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult.Yes == MessageBox.Show("是否退出系统？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
            {
                Environment.Exit(0);
            }
            else e.Cancel = true;
        }
    }
}


